﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;


namespace spline
{
    public partial class Form1 : Form
    {

        ZedGraphControl ZedGraph;
        GraphPane pane;

        public void draw_func()
        {           
            pane.CurveList.Clear();
            PointPairList list = new PointPairList();
            double xmin = -100;
            double xmax = 100;
            double xmin_limit = -10;
            double xmax_limit = 10;
            double ymin_limit = -5;
            double ymax_limit = 10;
            for (double x = xmin; x <= xmax; x +=0.1)
            {
                list.Add(x, Functions.f("1*"+textBox4.Text, x));
            }
            LineItem myCurve = pane.AddCurve("Sinc", list, Color.Blue, SymbolType.None);
            pane.XAxis.Scale.Min = xmin_limit;
            pane.XAxis.Scale.Max = xmax_limit;
            pane.YAxis.Scale.Min = ymin_limit;
            pane.YAxis.Scale.Max = ymax_limit;
            ZedGraph.AxisChange();
            ZedGraph.Invalidate();
        }

        public Form1()
        {
            InitializeComponent();
            ZedGraph = zedGraphControl1;
            pane = ZedGraph.GraphPane;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            pane.CurveList.Clear();
            ZedGraph.Invalidate();
            listBox1.Items.Clear();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double a = Convert.ToDouble(textBox2.Text);
            double b = Convert.ToDouble(textBox3.Text);
            //double eps = Convert.ToDouble(textBox1.Text);
            String func = textBox4.Text;
            Spline spl = new Spline(a, b, 40, 10, func);
            spl.makeSolution();
            List<double> solutions = spl.getSolution();
       
            foreach (double x in solutions) {
                listBox1.Items.Add(x.ToString());
            }
        }

        private void zedGraphControl1_MouseClick(object sender, MouseEventArgs e)
        {
            double x, y;
            zedGraphControl1.GraphPane.ReverseTransform(e.Location, out x, out y);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            draw_func();
        }

        private void textBox1_TextChanged(object sender, EventArgs e) {

        }
    }
}
